package com.tanhua.server.service;

import com.tanhua.dubbo.api.UserApi;
import com.tanhua.model.domain.User;
import com.tanhua.model.vo.HuanXinUserVo;
import com.tanhua.server.interceptor.UserHolder;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class HuanXinService {

    @DubboReference
    private UserApi userApi;

    /**
     * 查询当前用户的环信账户
     * 1.获取当前用户id，查询用户
     * */
    public HuanXinUserVo findHuanXinUser() {
        //1.获取当前用户id , 这里仅仅只保存了id 和手机号
        Long userId = UserHolder.getUserId();
        //2.通过API当前用户id获取用户对象
        User user = userApi.findById(userId);
        //3.判断对象是否为空
        if(user == null){
            return null;
        }
        //3.2如果不为空，则给前端返回一个vo对象
        return new HuanXinUserVo(user.getHxUser(),user.getPassword());
    }
}
